<meta name="content-type" content="text/html; charset=UTF-8" />
<div class="panel-heading panel-result-title">
	<h3 class="panel-title">查询结果</h3>
	<div class="btn-group btn-group-sm btn-gp-default">
		<button id="btn_add" type="button"
			class="btn btn-default panel-radius-left">添加</button>
		<button id="btn_edit" type="button"
			class="btn btn-default panel-radius-none">修改</button>
		<button id="btn_delete" type="button"
			class="btn btn-default panel-radius-none panel-border-left">删除</button>
		<button id="btn_group" type="button"
			class="btn btn-default panel-radius-right">指定用户组</button>
	</div>
</div>
<!-- #set(PaginatedList<User> pl) -->
<!--
		#set(
		pager = pl.pager,
		totalResults = pager.getCountOfTotalResults(),
		totalPages = pager.getCountOfTotalPages() * 1,
		pageSize = pager.pageSize,
		pageNo = pager.pageNo,
		prePageNo = pager.getPrevPageNo(),
		nextPageNo = pager.getNextPageNo()
		)
-->
<!--#if(pl)-->
	<table class="table table-bordered table-hover table-condensed tb" style="text-align: center; border-bottom: 1px solid #DDDDDD;">
		<tr>
			<td><input id="chkallIds" type="checkbox" /></td>
			<td>用户名称</td>
			<td>姓名</td>
			<td>出生年月</td>
			<td>邮箱</td>
			<td>电话</td>
			<td>用户组</td>
			<td>过期时间</td>
			<td>创建时间</td>
		<tr>
			<!--#for(User user : pl)-->
		<tr>
			<td><input name="chk_name" type="checkbox" value="${user.id}" /></td>
			<td>${user.username}</td>
			<td>${user.userDetail.name}</td>
			<td>${user.userDetail.birthday.format("yyyy-MM-dd")}</td>
			<td>${user.email}</td>
			<td>${user.userDetail.phone}</td>
			<td>${user.namecns }</td>
			<td>${user.expireTime.format("yyyy-MM-dd")}</td>
			<td>${user.createTime.format("yyyy-MM-dd")}</td>
		</tr>
		<!--#end-->
	</table>
	<div class="div_page main_div_page"></div>
<!-- #else -->
	<div class="panel-body">没有符合条件的数据</div>
<!-- #end -->
<form action="yueyogaAdmin/grantGroups.jhtml" method="post" name="groupForm">
	<div id="ubl_usergroups" class="panel-dialog-box panel-radius-all"
		style="width: 420px; display: none; z-index: 1000; min-height: 140px;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">指定用户组</h3>
			<br><br>
			<input type="hidden" id="hid_userId" name="userId" /> 
			<label for="selUserGroups" class="col-sm-1 control-label" style="margin-top:10px;">重定用户组</label>
			<div class="col-sm-8" style="margin-top:10px;">
				<!-- #set(List<Group> userGroups) -->
				<select class="selectpicker" multiple data-width="100%"
					name="groupId" id="selUserGroups">
					<option value=""></option>
					<!--#for(Group g: userGroups)-->
					<option value="${g.id}">${g.namecn}</option>
					<!-- #end -->
				</select>
			</div>
			<br><br>
			
			<div class="panel-btn-search" style="float: left; text-align: right; margin-top: 20px; margin-left: 110px;">
				<button type="button" id="btn_ok" class="btn-adet-default">保存</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="closeDIV()" class="btn-adet-default">取消</button>
			</div>
		</div>
	</div>
</form>
<!-- 列表分页 -->
<div class="paging-page">$!{include("paging_page.html")}</div>
<script type="text/javascript">
	function documentReady() {
		var groupMsg = "${groupMsg}";
		if (groupMsg == "success") {
			var d = alert("指定成功");
			setTimeout(function() {
				d.close().remove();
			}, 1000);
		} else if (groupMsg == "failure") {
			error("指定失败");
		}
		
		$("#selStatus").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	}
	$(function() {
		var ids = [];
		$("#btn_ok").click(function() {
			var group = $("#selUserGroups").val()+"";
			if(group.length>0&&group){
				document.groupForm.submit();
			}else{
				closeDIV();
				alert("请选择指定组!");
			}
		});

		$("#btn_no").click(function() {
			$("li").empty();
			$("#ugl_group").hide();
		});
		//指定用户组
		$("#btn_group").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if (ids.length == 0 || ids.length > 1) {
				alert("请选择一个用户,指定用户组");
				ids = [];
				return;
			} else {
				$("#selUserGroups").select2("val", "");
				closeDIV();
				$("#hid_userId").val(ids[0]);
				var url = "yueyogaAdmin/findUserGroupById.jhtml";
				$("#ugl_group").show();
				var ops = '';
				$.post(url, {
					userId : ids[0]
				}, function(resp) {
					var data = eval('(' + resp + ')');
					var str = '';
					var msg = eval('(' + data.msg + ')');
					if (data.success) {
						$.each(msg, function(i, val) {
							str = str + val.namecn + ',';
						});
						str = str.substring(0, str.length - 1);
						$("#myGroups").text(str);
					}
				});
				ids = [];
			}
		});
		//删除
		 $("#btn_delete").click(function() {
			var chks = $('input[name="chk_name"]:checked');
			if (chks.length > 0) {
				confirm("确定要删除吗?", function() {
					this.close();
					var url = "yueyogaAdmin/deleteUser.jhtml";
					var d = wait("正在删除,请稍等...");
					var ids = [];
					chks.each(function(index, item) {
						ids.push($(item).val());
					});
					$.post(url, {
						"ids" : ids
					}, function(msg) {
						if (msg == "success") {
							d.content("删除成功!");
							setTimeout(function() {
								d.close.remove();
							}, 300);
							//window.location.href = "yueyogaAdmin/searchBasicUsers.jhtml";	
							$("form[name='taskForm']").submit();
						} else {
							error("删除失败!");
						}
					});
				});
			} else {
				alert("请选择要删除的记录!");
				d.close();
			}
		}); 
		//--全选`反选
		$("#chkallIds").click(function() {
			if (this.checked) {
				$("input[name='chk_name']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='chk_name']").each(function() {
					this.checked = false;
				});
			}
		});

		$("#btn_add").click(function() {
			window.location.href = "yueyogaAdmin/toAddBasicUser.jhtml";
		});
		$("#btn_edit")
				.click(
						function() {
							var id = $('input[name="chk_name"]:checked');
							if (id.length == 1) {
								window.location.href = "yueyogaAdmin/toUpdateBasicUser.jhtml?userId="
										+ id.val();
							} else {
								alert("请选择一行进行修改!");
							}
						});
	});
	function closeDIV() {
		$("#ubl_usergroups").slideToggle(0);
	}
	function changePage(value) {
		value = value * 1;
		var totalPages = '${totalPages}';
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		$("#txtPageNumber").val(value);
		goToPage(value);
	}
	function goToPage(pageNo) {
		$("#hidPageNo").val(pageNo);
		//document.taskForm.submit();
		$("form[name='taskForm']").submit();
	}
</script>